package com.zhbr.mvp.presenter;

import com.zhbr.common.rx.BaseSubscriber;
import com.zhbr.entity.Account;
import com.zhbr.mvp.base.presenter.BasePresenter;
import com.zhbr.mvp.contract.RegisterContract;
import com.zhbr.mvp.model.RegisterModel;
import com.zhbr.mvp.ui.activity.RegisterActivity;

import java.util.HashMap;
import java.util.Map;

public class RegisterPresenter extends BasePresenter<RegisterActivity,RegisterModel> implements RegisterContract.Presenter {
    @Override
    protected RegisterModel createModule() {
        return new RegisterModel();
    }

    @Override
    public void register(String nickname,String phone, String password) {
        Map params = new HashMap();
        params.put("nickName",nickname);
        params.put("phone",phone);
        params.put("password",password);

        mModel.register(params, new BaseSubscriber<Account>() {
            @Override
            public void onSuccess(Account data) {
                if (isViewAttach()){
                    getView().onRegisterSuccess(data);
                }
            }

            @Override
            public void onFailed(Throwable ex, String code, String msg) {
                getView().onRegisterFail(ex, code, msg);
            }

            @Override
            public void onError() {
                onNetError();
            }
        });
    }
}
